package cn.stylefeng.guns.modular.feature.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.feature.entity.Feature;
import cn.stylefeng.guns.modular.feature.model.params.FeatureParam;
import cn.stylefeng.guns.modular.feature.service.FeatureService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 功能表控制器
 *
 * @author jalor
 * @Date 2019-10-20 13:31:24
 */
@Controller
@RequestMapping("/feature")
@Api("功能控制器")
public class FeatureController extends BaseController {

    private String PREFIX = "/feature";

    @Autowired
    private FeatureService featureService;

    /**
     * 跳转到主页面
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/feature.html";
    }

    /**
     * 新增页面
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/feature_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/feature_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(FeatureParam featureParam) {
        this.featureService.add(featureParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(FeatureParam featureParam) {
        this.featureService.update(featureParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(FeatureParam featureParam) {
        this.featureService.delete(featureParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(FeatureParam featureParam) {
        Feature detail = this.featureService.getById(featureParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jalor
     * @Date 2019-10-20
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(FeatureParam featureParam) {
        return this.featureService.findPageBySpec(featureParam);
    }

    @ApiOperation("获取所有功能(下拉框使用)")
    @ResponseBody
    @PostMapping("/listAll")
    public List<Feature> listAll(@ApiParam(value = "产品ID", required = true) @RequestParam String productId,
                                 @ApiParam("编号") @RequestParam(required = false) String code,
                                 @ApiParam("名称") @RequestParam(required = false) String name) {
        return featureService.listAll(productId, code, name);
    }
}


